<template>
  <div class="app-container">
    <div class="syl-group">
      <el-form ref="queryForm" :model="queryParams" :inline="true" @submit.native.prevent>
        <el-form-item label="企业名称:" prop="companyName">
          <el-input
            v-model.trim="queryParams.companyName"
            placeholder="请输入"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="equWristbandList" :header-cell-style="{background:'#F3F9FF',color:'#333333',fontWeight: 600}">
        <el-table-column label="编号" align="center" prop="id" type="index" />
        <el-table-column label="企业名称" align="center" prop="companyName" :show-overflow-tooltip="true" />
        <el-table-column label="用餐人数" align="center" prop="mealPeopleNum" />
        <el-table-column label="联系人" align="center" prop="contactName" />
        <el-table-column label="联系电话" align="center" prop="contactPhone" />
        <el-table-column label="地址" align="center" prop="address" :show-overflow-tooltip="true" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <router-link :to="{path: '/system/enterprise/info',query:{id:scope.row.id}}">
              <el-button
                size="mini"
                type="text"
              >查看
              </el-button>
            </router-link>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>
<script>
import { getListByName } from '@/api/system/enterprise'
export default {
  name: 'Index',
  data() {
    return {
      // 遮罩层
      loading: false,
      lodaing: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 5,
      // 企业名称表格数据
      equWristbandList: [
      ],
      // 状态
      options: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyName: undefined
      },
      // 表单参数
      form: {
        imei: undefined,
        icNum: undefined,
        suplyCompany: undefined,
        useStatus: '0'
      },
      // 表单校验
      rules: {
        imei: [
          { required: true, message: '请输入手环号', trigger: 'blur' },
          {
            pattern: /^[0-9a-zA-Z]*$/g,
            message: '手环号不能输入汉字和特殊字符',
            trigger: 'blur'
          }
        ],
        icNum: [
          { required: true, message: '请输入卡编号', trigger: 'blur' },
          {
            pattern: /^[0-9]*$/,
            message: '卡号为数字',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询电子手环列表 */
    getList() {
      getListByName(this.queryParams).then(res => {
        const { total, records } = res.data
        this.total = total
        this.equWristbandList = records
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        imei: undefined,
        icNum: undefined,
        suplyCompany: undefined,
        deptId: undefined,
        useStatus: '0',
        status: undefined,
        power: undefined,
        delFlag: undefined,
        createDate: undefined,
        createBy: undefined,
        updateDate: undefined,
        updateBy: undefined,
        upload: undefined,
        people: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    handleUpdate(row) {
      console.log(row)
    }
  }
}
</script>
